package com.gzx.spring.drools.controller;

import com.gzx.risk.core.apis.context.ApiContext;
import com.gzx.risk.core.pojo.CommonResult;
import com.gzx.risk.core.pojo.UserInfo;
import com.gzx.risk.core.tags.CommonLog;
import com.gzx.spring.drools.job.DroolsJob;
import com.gzx.spring.drools.service.DroolsService;
import com.gzx.spring.drools.service.RiskWorkService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "drools")
@RestController
@Validated
@RequestMapping("/api/drools")
@Slf4j
public class DroolsController {
	@Resource
	private DroolsService droolsService;
	@Resource
	private RiskWorkService riskWorkService;
	@Resource
	private DroolsJob droolsJob;

    @Operation(summary = "exec")
	@CommonLog("exec")
	@PostMapping("/exec")
	public CommonResult<String> check(@RequestParam(name = "name", defaultValue = "吴岩") String name,
			@RequestParam(name = "id", defaultValue = "210727197902096937") String id,
			@RequestParam(name = "phone", defaultValue = "13488774341") String phone,
			@RequestParam(name = "idLastdate", defaultValue = "2049-12-31") String idLastdate,
			@RequestParam(name = "authDate", defaultValue = "20250804-20250830") String authDate,
			@RequestParam(name = "lastRefuseDate", defaultValue = "2025-08-01") String lastRefuseDate)
			throws Exception {
		ApiContext ctx = new ApiContext();
		UserInfo userInfo = new UserInfo();
		userInfo.setName(name);
		userInfo.setId(id);
		userInfo.setPhone(phone);
		userInfo.setIdLastdate(idLastdate);
		ctx.setUserInfo(userInfo);

		ctx.setAuthDate(authDate);
		ctx.setLastRefuseDate(lastRefuseDate);
		droolsService.exec(ctx);
		return CommonResult.ok("result:" + ctx.getRuleResult());
	}

	@Operation(summary = "riskOrder")
	@CommonLog("riskOrder")
	@PostMapping("/riskOrder")
	public CommonResult<String> riskOrder(@RequestParam(name = "oid", defaultValue = "19") int oid) throws Exception {
		log.info("验证风控流程:{}", oid);
		riskWorkService.exec(oid);
		return CommonResult.ok();
	}

	@Operation(summary = "riskOrders")
	@CommonLog("riskOrders")
	@PostMapping("/riskOrders")
	public CommonResult<String> riskOrders() throws Exception {
		riskWorkService.exec();
		return CommonResult.ok();
	}

	@GetMapping("/notifyReport")
	public CommonResult<String> notifyReport() throws Exception {
		droolsJob.notifyReport();
		return CommonResult.ok();
	}

    @GetMapping("/notifyReportTemp")
    public CommonResult<String> notifyReportTemp() throws Exception {
        droolsJob.notifyReportTemp();
        return CommonResult.ok();
    }
}
